﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// users 的摘要说明
/// </summary>
public class users : SQLHelper
{
    private string _m_id;
    private string _k_id;
    private string _p_id;
    private string _m_password;
    private string _p_password;
    private string _p_name;
    private string _p_phone;
    private string _k_name;
    private string _k_sex;
    private string _k_birthday;
    private string _k_address;
    private string _k_phone;
    private string _k_area;
    private string _k_street;
    private string _p_oldps;
    public string m_id
    {
        get { return _m_id; }
        set { _m_id = value; }
    }
    public string k_id
    {
        get { return _k_id; }
        set { _k_id = value; }
    }
    public string p_id
    {
        get { return _p_id ; }
        set { _p_id = value; }
    }
    public string m_password
    {
        get { return _m_password ; }
        set { _m_password  = value; }
    }
    public string p_password
    {
        get { return _p_password ; }
        set { _p_password  = value; }
    }
    public string p_name
    {
        get { return _p_name ; }
        set { _p_name  = value; }
    }
    public string p_phone
    {
        get { return _p_phone ; }
        set { _p_phone  = value; }
    }
    public string k_name
    {
        get { return _k_name ; }
        set { _k_name  = value; }
    }
    public string k_sex
    {
        get { return _k_sex; }
        set { _k_sex  = value; }
    }
    public string k_birthday
    {
        get { return _k_birthday ; }
        set { _k_birthday  = value; }
    }
    public string k_phone
    {
        get { return _k_phone ; }
        set { _k_phone  = value; }
    }
    public string k_area
    {
        get { return _k_area; }
        set { _k_area = value; }
    }
    public string k_street
    {
        get { return _k_street; }
        set { _k_street = value; }
    }
    public string k_address
    {
        get { return _k_address; }
        set { _k_address = value; }
    }
    public string p_oldps
    {
        get { return _p_oldps; }
        set { _p_oldps = value; }
    }
    public users()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    //查找ID是否重复
    public int isExist(users tmp)
    {

        string sql = "select count(*)from parent where p_id='" + p_id  + "'";
        int result = 0;
        result = tmp.ExeScale(sql);
        return result;
    }

    //登录
    public int login1(users tmp)
    {
        string sql = "select count(*)from manager where (m_id='" + tmp.m_id   + "' and m_password='" + tmp.m_password  + "')";
        int result = 0;
        result = tmp.ExeScale(sql);
        return result;
    }

    public int login(users tmp)
    {
        string sql = "select count(*)from parent where (p_id='" + tmp.m_id  + "' and p_password='" + tmp.m_password  + "')";
        int result = 0;
        result = tmp.ExeScale(sql);
        return result;
    }

    //注册
    public void ZhuCe(users h)
    {
        string sql = "insert into parent(id,password) values('" + h.p_id  + "','" + h.p_password  + "');";
        h.ExeNonQuery(sql);
    }
    //提交信息
    public void TiJiao(users h)
    {
        string sql = "insert into kinder(name,sex,birthday,phone,area,street,address) values('" + h.k_name + "','" + h.k_sex + "','" + h.k_birthday + "','" + h.k_phone + "','" + h.k_area + "','" + h.k_street + "','" + h.k_address + "');";
        h.ExeNonQuery(sql);
    }


   /* //更新信息
    public void GenXin(users h)
    {
        string sql = "update Grade  set  Password='" + h.ps + "',Name='" + h.name +
                "',Chinese='" + h.chinese + "',Math='" + h.math +
                "' ,English='" + h.english + "', Physics='" + h.physics + "', Chemistry='" + h.chemistry + "', Biology ='" + h.biology + "' where ID='" + h.id + "'";
        h.ExeNonQuery(sql);
    }
    //更新课程表
    public void GX(users h)
    {
        string sql = "update Kecheng set Monday='" + h.monday + "',Tuesday='" + h.tuesday + "',Wednesday='" + h.wednesday + "',Thursday='" + h.thursday + "',Friday='" + h.friday + "'where Period='" + h.period + "'";
        h.ExeNonQuery(sql);
    }*/

    //预读数据库
    public SqlDataReader ReadInform(users h)
    {
        string sql = "select * from parent where ID='" + h.p_id  + "'";
        return h.ExeReader(sql);
    }
    //查找身份证号是否存在

    public int parent(users h)
    {
        string sql = "select count(*) from parent where p_id='" + h.p_id  + "'";
        int result = 0;
        result = h.ExeScale(sql);
        return result;
    }
    public DataSet GetAlluser(users us)
    {

        string sql = "select * from kinder ";
        DataSet ds = us.GetDs(sql);
        return ds;
    }


   /* //显示查找学生
    public SqlDataReader SelectStu(users h)
    {
        string sql = "select * from Grade where Name='" + h.name + "'";
        return h.ExeReader(sql);
    }*/

    //删除学生
    public void Delete(users h)
    {
        string sql = "delete from kinder where name='" + h.k_name  + "'";
        h.ExeNonQuery(sql);
    }

    public DataSet GetAllkinder()
    {
        string sql = "select * from kinder ";
        users tmp = new users();
        DataSet ds = tmp.GetDs(sql);
        return ds;

    }

    /*public DataSet GetAllClass()
    {
        string sql = "select * from Kecheng ";
        users tmp = new users();
        DataSet ds = tmp.GetDs(sql);
        return ds;

    }*/
    public DataSet GetOnekinder(users tmp)
    {
        string sql = "select * from kinder where k_name='" + tmp.k_name  + "'";
        DataSet ds = tmp.GetDs(sql);
        return ds;
    }
    public int  Sub_Delete(users h)
    {
        string sql = "delete from kinder where k_id='" + h.k_id  + "'";
        int result = h.ExeNonQuery(sql);
        return result;
    }
    /*//更新一个学生的信息
    public int Updateoneuser(users tmp)
    {
        string sql = "update Grade  set  Name='" + tmp.name + "',Password='" + tmp.ps +
                "',Chinese='" + tmp.chinese + "',Math='" + tmp.math +
                "' ,English='" + tmp.english + "', Physics='" + tmp.physics + "', Chemistry  ='" + tmp.chemistry + "', Biology='" + tmp.biology + "' where ID='" + tmp.id + "'";
        int result = tmp.ExeNonQuery(sql);
        return result;
    }
    public int Deleteoneuser(users tmp)
    {
        string sql = "delete  from Grade where ID='" + tmp.id + "'";
        int result = tmp.ExeNonQuery(sql);
        return result;
    }
    public SqlDataReader GetOneUser(users tmp)
    {
        string sql = "select * from Grade where u_ID='" + tmp.id + "'";
        SqlDataReader rd = tmp.ExeReader(sql);
        return rd;
    }*/

    public void updataps(users tmp)
    {
        string sql = "update parent set p_password='" + tmp.p_password  + "' where p_id='"+ tmp.p_id +"'";
        tmp.ExeNonQuery(sql);
    }

    public int password(users tmp)
    {
        string sql = "select count(*) from parent where (p_id='" + tmp.p_id  + "' and p_password='" + tmp.p_oldps  + "')";
        return tmp.ExeScale(sql);
    }

    public int select_xiaohai(users tmp)
    {
        string sql = "select count(*) from kinder where k_id='" + tmp.m_id + "'";
        int result = 0;
        result = tmp.ExeScale(sql);
        return result;
    }
    //public void updataps(users tmp)
    //{
    //    string sql = "update parent set p_password='" + tmp.p_password  + "'";
    //    tmp.ExeNonQuery(sql);
    //}
    //public int password(users tmp)
    //{
    //    string sql = "select count(*) from parent where (p_id='" + tmp.p_id + "' and p_password='" + tmp.p_oldps + "')";
    //    return tmp.ExeScale(sql);
    //}


    public void Zhu(users tmp)
    {
        string sql = "insert into parent( p_name,p_id,p_password,p_phone) values('" + tmp.p_name + "','" + tmp.p_id + "','" + tmp.p_password + "','" + tmp.p_phone + "')";
        tmp.ExeNonQuery(sql);
    }
}